# increase this to make clients auto-update
BUILD=4

all: cncnet.exe

bin2rc:
	gcc -Wall -g -o bin2rc bin2rc.c
        
res/cncnet.dll: cncnet.c inject.c ../ingame/thipx32.c ../ingame/wsock32.c
	i586-mingw32msvc-gcc -Wl,--enable-stdcall-fixup -Wall -O2 -shared -I../ingame/ -s -o res/cncnet.dll cncnet.c ../ingame/thipx32.c ../ingame/wsock32.c ../ingame/sockets.c ../ingame/config.c -lws2_32 -lpsapi
	upx -qq --best res/cncnet.dll

res/launcher.rc: res/cncnet.dll res/launcher.rc.in bin2rc
	sed "s/__BUILD__/$(BUILD)/" res/launcher.rc.in > res/launcher.rc
	./bin2rc 256 < res/cncnet.dll >> res/launcher.rc

resource.o: res/launcher.rc
	i586-mingw32msvc-windres -J rc res/launcher.rc resource.o

cncnet.exe: resource.o launcher.c inject.c updater.c
	i586-mingw32msvc-gcc -DBUILD=$(BUILD) -Wl,--enable-stdcall-fixup -Wall -O2 -Iext -Lext -s -o cncnet.exe launcher.c updater.c resource.o -lwinhttp
	upx -qq --best cncnet.exe

clean:
	rm -f *.o cncnet.exe res/cncnet.dll bin2rc res/launcher.rc
